package com.hup.minicontroller.server.androidService;

import android.accessibilityservice.AccessibilityService;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;

import com.hup.minicontroller.server.ServerApplication;
import com.hup.minicontroller.server.mvp.IMainView;

/**
 * 无障碍服务,
 * 启动服务说明:
 * .需要用户手动在系统设置中启动服务
 * .一旦用户启动服务,则设备重启后会自启动本服务,不需要 RECEIVE_BOOT_COMPLETED 权限
 *
 * @author hugan
 * @date 2023/1/3
 */
public class MyAccessibilityService extends AccessibilityService {
    private static final String TAG = MyAccessibilityService.class.getSimpleName();

    @Override
    protected void onServiceConnected() {
        Log.i(TAG, "onServiceConnected: ");
        ServerApplication.putBean(this);
        ServerApplication.executeIfExist(IMainView.class, IMainView::onControlConfigChanged);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {

    }

    @Override
    public void onInterrupt() {
        Log.i(TAG, "onInterrupt: ");
        ServerApplication.removeBean(getClass());
        ServerApplication.executeIfExist(IMainView.class, IMainView::onControlConfigChanged);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
        ServerApplication.removeBean(getClass());
        ServerApplication.executeIfExist(IMainView.class, IMainView::onControlConfigChanged);
    }

}
